#!/bin/sh
#
# Incoming Slackware automated installation script
#
#   Copyright 2013 Coastal Carolina University
#   Copyright 2007 Clemson University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


# Slackware automated install script
# Author: Michael Fenn

# FDISK
fdisk /dev/sda << EOF
o
n
p
1

+15000M
t
FD

n
p
2

+2000M
t
2
82
n
p
3


t
3
FD
p
w
EOF

sleep 10

fdisk /dev/sdb << EOF
o
n
p
1

+15000M
t
FD

n
p
2

+2000M
t
2
82
n
p
3


t
3
FD
p
w
EOF

sleep 10

# Initialize and mount fs
mkswap /dev/sdb2
swapon /dev/sdb2
mkswap /dev/sda2
swapon /dev/sda2

echo "Setting up root RAID..."
mdadm --create -R --verbose /dev/md1 --level=1 \
       --raid-devices=2 /dev/sda1 /dev/sdb1
cat /proc/mdstat
mkfs.ext2 -j /dev/md1

mkdir /mnt/root
mount /dev/md1 /mnt/root
ls /mnt/root
mdadm --detail --scan --verbose

mkdir /mnt/root/etc
mdadm --detail --scan --verbose > /mnt/root/etc/mdadm.conf

sleep 10

echo "Setting up distributed filesystem RAID..."
mdadm --create -R --verbose /dev/md0 --level=0 \
       --raid-devices=2 /dev/sda3 /dev/sdb3
cat /proc/mdstat
mkfs.ext2 -j /dev/md0

mkdir /mnt/root/dfs
mount /dev/md0 /mnt/root/dfs
ls /mnt/root/dfs
mdadm --detail --scan --verbose

mkdir /mnt/root/etc
mdadm --detail --scan --verbose > /mnt/root/etc/mdadm.conf

sleep 10

# Config network
/bin/network << EOF


EOF

ifconfig eth0 up
dhcpcd -n -H eth0
/bin/hostname
sleep 5

/sbin/rpc.portmap
mkdir /mnt/pkgs
mount -t nfs 10.42.8.8:/home/pkgs /mnt/pkgs
ls /mnt/pkgs
sleep 5

# Install pkgs
for p in a ap d e f k kde kdei l n t tcl x xap y zzz; do
	installpkg -root /mnt/root /mnt/pkgs/$p/*.tgz
done

installpkg -root /mnt/root /mnt/pkgs/oiltank*.tgz

# Post install
echo "Going post-install"
sleep 5

/etc/rc.d/slackware-postinstall.sh

